<template>
  <div class="uploadFile">
    <h3 v-if="data.type != 'sm3'" class="title">文件加密操作</h3>
    <h3 v-if="data.type == 'sm3'" class="title">文件Hash操作</h3>
    <el-form
      status-icon
      label-width="150px"
      class="demo-ruleForm"
    >
      <h4 v-if="data.type != 'sm3'" style="padding-left: 150px">请输入密钥:</h4>
      <el-input v-if="data.type != 'sm3'" v-model="data.key" style="padding-left: 150px; width:96%"></el-input>

      <el-form-item label="加密类型" prop="data.type">
        <el-radio-group v-model="data.type">
          <el-radio label="zuc"  border></el-radio>
          <el-radio label="sm2" border></el-radio>
          <el-radio label="sm4"  border></el-radio>
          <el-radio label="sm3" border>文件hash</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-upload
        class="avatar-uploader"
          :headers="headers"
          :action="action"
          :data="data"
          :on-remove="remove"
          multiple
          :file-list="fileList"
      >
         <el-button
            style="margin-left: 150px; margin-bottom: 20px; height: 40px; align-items: center"
            type="primary"
            >上传<i class="el-icon-upload el-icon--right"></i
          ></el-button>
      </el-upload>
    </el-form>
  </div>
</template>

<script>
import cookie from "js-cookie";
import axios from "../request/axios";
import userRequest from "../request/user";
export default {
  data() {
    return {
      action: axios.defaults.baseURL + "file/upload",
      data: {
        key:'',
        dataId: Math.random().toString(36).substr(3, 6) + Date.now().toString(),
        type: ""
      },

       headers: {
        satoken: cookie.get("satoken"),
      },
      fileList: []
    };
  },

  methods: {
    // 清空表单
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
    remove(file) {
      console.log(this.data.dataId)
      userRequest.deleteFile(this.data.dataId)
        return this.$confirm(`确定移除 ${ file.name }？`);
      }
  },

  created() {}
};
</script>

<style lang="scss" scoped>
.uploadFile {
  overflow: hidden;

  ::v-deep .title {
    margin: 36px;
    text-align: center;
    font-size: 20px;
  }
  ::v-deep .demo-ruleForm {
    width: 500px;
    margin: 30px auto;
  }
  ::v-deep .el-input__inner {
    height: 45px;
    font-size: 16px;
  }
  ::v-deep .el-form-item__label {
    font-size: 16px;
    position: relative;
    top: 12px;
  }
  ::v-deep .el-form-item__content {
    margin-top: 10px;
    height: 50px;
    display: flex;
  }
  ::v-deep .el-form-item__error {
    font-size: 16px;
  }

  ::v-deep .el-select-dropdown__item {
    display: flex;
    justify-content: center;
  }
  ::v-deep .el-radio-group {
    width: 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: -1px;
  }
}
</style>